package com.converse.diamondreader.customized;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;

import com.google.mlkit.vision.text.Text;

/**
 * Author: Administrator
 * Date: 2021/12/29
 * Project: DiamondReader
 * Description:
 */
public class FrameGraphic extends GraphicOverlay.Graphic {

    private GraphicOverlay mOverlay;
    private final Point[] mCornerPoints;
    private final Paint rectPaint;
    private static final int TEXT_COLOR = Color.RED;
    private static final float TEXT_SIZE = 54.0f;
    private static final float STROKE_WIDTH = 4.0f;
    private Matrix mMatrix;


    public FrameGraphic(GraphicOverlay overlay, Text.Line line) {
        super(overlay);
        mCornerPoints = line.getCornerPoints();
        rectPaint = new Paint();
        rectPaint.setColor(TEXT_COLOR);
        rectPaint.setStyle(Paint.Style.STROKE);
        rectPaint.setStrokeWidth(STROKE_WIDTH);
        mMatrix=new Matrix();
        mMatrix.setRotate(90);
//        mMatrix.postTranslate((1200-720)/2, (1600-1472)/2);
//        mMatrix.postScale(720/1200, 1472/1600);
//        mMatrix.preTranslate((7200-1200)/2, (1472-1600)/2);
    }

    @Override
    public void draw(Canvas canvas) {
        if (mCornerPoints != null) {
            Path path = new Path();
            if (mCornerPoints.length > 1) {
                path.moveTo(mCornerPoints[0].x, mCornerPoints[0].y);
                for (int i = 1; i < mCornerPoints.length; i++) {
                    path.lineTo(mCornerPoints[i].x, mCornerPoints[i].y);
                    if (i == mCornerPoints.length - 1) {
                        path.lineTo(mCornerPoints[0].x, mCornerPoints[0].y);
                    }
                }
                canvas.setMatrix(mMatrix);
                canvas.drawPath(path, rectPaint);
            }
        }

    }
}
